// import { CONVERSATION_ID_INFO } from '../base/chat/constants'
// import { fetchAccessToken } from '@/services/share'
const CONVERSATION_ID_INFO = ''

const fetchAccessToken = (args: any): any => { }

export const checkOrSetAccessToken = async () => {
  const sharedToken = globalThis.location.pathname.split('/').slice(-1)[0]
  const accessToken = localStorage.getItem('token') || JSON.stringify({ [sharedToken]: '' })
  let accessTokenJson = { [sharedToken]: '' }
  console.log('accessTokenJson', accessTokenJson);
  // try {
  //   accessTokenJson = JSON.parse(accessToken)
  // }
  // catch (e) {

  // }
  // if (!accessTokenJson[sharedToken]) {
    // const res = await fetchAccessToken(sharedToken)
    // accessTokenJson[sharedToken] = res.access_token
    //{"imRaN4trx1uaBP9b":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJmMzkzZDYxNC1kNWI3LTQ0MzktODU0Ny04ODI5MmFkOGE5YjIiLCJzdWIiOiJXZWIgQVBJIFBhc3Nwb3J0IiwiYXBwX2lkIjoiZjM5M2Q2MTQtZDViNy00NDM5LTg1NDctODgyOTJhZDhhOWIyIiwiYXBwX2NvZGUiOiJpbVJhTjR0cngxdWFCUDliIiwiZW5kX3VzZXJfaWQiOiI3ZmM4NGU5OS1mYTFkLTQ4ZjMtYjUwNi02ODY3YjA4MGUwMjQifQ.hsxQv1FrAlnv-e2G-QSyLMdp6U7TK4t5MH_hlNQ3iec","9ODan2oQLqNkpahH":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI5ZTIwODA2Ny0yODRiLTQ5YWEtOTU5NC1kNWNiNDQzZDRmYmIiLCJzdWIiOiJXZWIgQVBJIFBhc3Nwb3J0IiwiYXBwX2lkIjoiOWUyMDgwNjctMjg0Yi00OWFhLTk1OTQtZDVjYjQ0M2Q0ZmJiIiwiYXBwX2NvZGUiOiI5T0RhbjJvUUxxTmtwYWhIIiwiZW5kX3VzZXJfaWQiOiJkNjA4MzJlZS0zYTY1LTQxZWQtYWVmOC04MWFmY2I3MjBhNWUifQ.fAf12DZb2iIlhd5FKU4by59ftOLAapjqSAAfVvMpsJs"}
    // localStorage.setItem('token', JSON.stringify(accessTokenJson))
    let t = `{"imRaN4trx1uaBP9b":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJmMzkzZDYxNC1kNWI3LTQ0MzktODU0Ny04ODI5MmFkOGE5YjIiLCJzdWIiOiJXZWIgQVBJIFBhc3Nwb3J0IiwiYXBwX2lkIjoiZjM5M2Q2MTQtZDViNy00NDM5LTg1NDctODgyOTJhZDhhOWIyIiwiYXBwX2NvZGUiOiJpbVJhTjR0cngxdWFCUDliIiwiZW5kX3VzZXJfaWQiOiI3ZmM4NGU5OS1mYTFkLTQ4ZjMtYjUwNi02ODY3YjA4MGUwMjQifQ.hsxQv1FrAlnv-e2G-QSyLMdp6U7TK4t5MH_hlNQ3iec","9ODan2oQLqNkpahH":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI5ZTIwODA2Ny0yODRiLTQ5YWEtOTU5NC1kNWNiNDQzZDRmYmIiLCJzdWIiOiJXZWIgQVBJIFBhc3Nwb3J0IiwiYXBwX2lkIjoiOWUyMDgwNjctMjg0Yi00OWFhLTk1OTQtZDVjYjQ0M2Q0ZmJiIiwiYXBwX2NvZGUiOiI5T0RhbjJvUUxxTmtwYWhIIiwiZW5kX3VzZXJfaWQiOiJkNjA4MzJlZS0zYTY1LTQxZWQtYWVmOC04MWFmY2I3MjBhNWUifQ.fAf12DZb2iIlhd5FKU4by59ftOLAapjqSAAfVvMpsJs"}`
    localStorage.setItem('token', t)
  // }
}

export const setAccessToken = async (sharedToken: string, token: string) => {
  const accessToken = localStorage.getItem('token') || JSON.stringify({ [sharedToken]: '' })
  let accessTokenJson = { [sharedToken]: '' }
  try {
    accessTokenJson = JSON.parse(accessToken)
  }
  catch (e) {

  }

  localStorage.removeItem(CONVERSATION_ID_INFO)

  accessTokenJson[sharedToken] = token
  localStorage.setItem('token', JSON.stringify(accessTokenJson))
}

export const removeAccessToken = () => {
  const sharedToken = globalThis.location.pathname.split('/').slice(-1)[0]

  const accessToken = localStorage.getItem('token') || JSON.stringify({ [sharedToken]: '' })
  let accessTokenJson = { [sharedToken]: '' }
  try {
    accessTokenJson = JSON.parse(accessToken)
  }
  catch (e) {

  }

  localStorage.removeItem(CONVERSATION_ID_INFO)

  delete accessTokenJson[sharedToken]
  localStorage.setItem('token', JSON.stringify(accessTokenJson))
}
